package com.ruoyi.system.service.impl;

import java.time.LocalDate;
import java.time.Month;
import java.util.List;

import com.ruoyi.system.domain.LeaveRetireUser;
import com.ruoyi.system.mapper.LeaveRetireUserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.PensionRecordMapper;
import com.ruoyi.system.domain.PensionRecord;
import com.ruoyi.system.service.IPensionRecordService;

/**
 * 退休金发放Service业务层处理
 * 
 * @author ruoyi
 * @date 2023-12-16
 */
@Service
public class PensionRecordServiceImpl implements IPensionRecordService 
{
    @Autowired
    private PensionRecordMapper pensionRecordMapper;

    @Autowired
    private LeaveRetireUserMapper leaveRetireUserMapper;

    /**
     * 查询退休金发放
     * 
     * @param id 退休金发放主键
     * @return 退休金发放
     */
    @Override
    public PensionRecord selectPensionRecordById(Long id)
    {
        return pensionRecordMapper.selectPensionRecordById(id);
    }

    /**
     * 查询退休金发放列表
     * 
     * @param pensionRecord 退休金发放
     * @return 退休金发放
     */
    @Override
    public List<PensionRecord> selectPensionRecordList(PensionRecord pensionRecord)
    {
        return pensionRecordMapper.selectPensionRecordList(pensionRecord);
    }

    /**
     * 新增退休金发放
     * 
     * @param pensionRecord 退休金发放
     * @return 结果
     */
    @Override
    public int insertPensionRecord(PensionRecord pensionRecord)
    {
        //用户点击发放退休金
        Long userId = pensionRecord.getUserId();
        LeaveRetireUser leaveRetireUser = leaveRetireUserMapper.selectLeaveRetireUserByUserId(userId);
        pensionRecord.setPension(leaveRetireUser.getPension());
        //获取当前日期
        //获取当前日期
        LocalDate now = LocalDate.now();
        int month = now.getMonthValue(); // 获取月份数值
        String title = month + "月份退休金";
        pensionRecord.setTitle(title);

        return pensionRecordMapper.insertPensionRecord(pensionRecord);
    }

    /**
     * 修改退休金发放
     * 
     * @param pensionRecord 退休金发放
     * @return 结果
     */
    @Override
    public int updatePensionRecord(PensionRecord pensionRecord)
    {
        return pensionRecordMapper.updatePensionRecord(pensionRecord);
    }

    /**
     * 批量删除退休金发放
     * 
     * @param ids 需要删除的退休金发放主键
     * @return 结果
     */
    @Override
    public int deletePensionRecordByIds(Long[] ids)
    {
        return pensionRecordMapper.deletePensionRecordByIds(ids);
    }

    /**
     * 删除退休金发放信息
     * 
     * @param id 退休金发放主键
     * @return 结果
     */
    @Override
    public int deletePensionRecordById(Long id)
    {
        return pensionRecordMapper.deletePensionRecordById(id);
    }
}
